/*  
 *  Copyright (c) 2008 Adrian Necimal <necimal@gmail.com>
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

function SSProviderService() {
  this.wrappedJSObject = this;
};

SSProviderService.prototype = {
  classDescription: "SuperSidebar Provider Service Javascript XPCOM Component",
  classID: Components.ID("{44D24885-7208-44e3-A544-7838203248FB}"),
  contractID: "@necimal.com/supersidebar/providerservice;1",
  QueryInterface: XPCOMUtils.generateQI([]),
  providers: new Array()
}

SSProviderService.prototype.registerProvider = function(ssProvider) {
  // check that the provider hasn't already been registered
  for (i=0; i<this.providers.length; i++) {
    if (this.providers[i].providerID == ssProvider.providerID) { return; }
  }
  
  // register the new provider
  this.providers.push(ssProvider);
}

SSProviderService.prototype.getProviders = function() {
  return this.providers;
}

// notify all content providers of a new mediaItem, with a listener to notify when content is ready
SSProviderService.prototype.triggerProviders = function(mediaItem, contentListener) {
  for (i=0; i<this.providers.length; i++) {
    this.providers[i].getContent(mediaItem, contentListener);
  }
}

function NSGetModule(compMgr, fileSpec) {
  return XPCOMUtils.generateModule([SSProviderService]);
}
